log using "/Users/tgrillos/Dropbox/3 KENYA/Busara ERSS Experiment/3 BJPS Submission/Replication Data/ReplicationLog.smcl", replace

********************************************************************************
***************************Replication Code*************************************
********************************************************************************

********************************************************************************
**Participation Improves Collective Decisions (When It Involves Deliberation):
**Experimental Evidence from Kenya
*******British Journal of Political Science, 2021
*******Tara Grillos
*******Assistant Professor, Department of Political Science, Purdue University
*******tgrillos@purdue.edu 
********************************************************************************


*Set working directory
cd "/Users/tgrillos/Dropbox/3 KENYA/Busara ERSS Experiment/3 BJPS Submission/Replication Data"
*open dataset:
use "GroupDecisionData.dta"


*Set up data for analysis:

*set scheme for plots and graphs
set scheme cleanplots

*drop one group that played with a different number of players
drop if SizeGroup !=5
*drop the session that had repeat participants:
drop if Session==21

*create marker to aid group-level analyses:		
bysort Session group: gen seq=_n

*create shortcut list of control variables for use in later models:
global Controls = "Female Age educ_years i.EverMarried NoofChildren altruism KnewOthers prop_female numCoethnic SizeSession"
	
	

********************************************************************************
********Figure 1: Steps in Experimental Design

*No stata output was used in creation of this figure. 
*It is not part of the data analysis but rather is a schematic of the  
*overarching research design.


********************************************************************************
*****Appendix A: Descriptive Statistics**********************

*Calculate descriptive statistics for balance table
*net install desctable, from("https://tdmize.github.io/data/desctable")

*first for full sample:
desctable i.Female Age educ_years i.EverMarried NoofChildren i.altruism ///
	i.BQ5_preferedTask i.AssignedTask practiceLetterCounting_numCorrec ///
	practiceSliders_numCorrect practiceStroopsSetCorrect ///
	Main_Effort Main_Effort_norm ///
	, filename("descriptives") 

*next by treatment group
desctable i.Female Age educ_years i.EverMarried NoofChildren i.altruism ///
	i.BQ5_preferedTask i.AssignedTask practiceLetterCounting_numCorrec ///
	practiceSliders_numCorrect practiceStroopsSetCorrect ///
	Main_Effort Main_Effort_norm ///
	, filename("descriptives_treatment") group(treat_num)

*Calculate p values for balance table:
orth_out Female Age educ_years EverMarried NoofChildren altruism ///
	practiceLetterCounting_numCorrec ///
	practiceSliders_numCorrect practiceStroopsSetCorrect ///
	Main_Effort Main_Effort_norm ///
	, by(treat_num) pcompare	

orth_out Task1 Task2 Task3  ///
	, by(treat_num) pcompare		

tabulate BQ5_preferedTask, generate (PrefTask)
orth_out PrefTask1 PrefTask2 PrefTask3  ///
	, by(treat_num) pcompare		
drop PrefTask*


********************************************************************************
********Appendix B: Statistical Power Calculations	

*No stata output was used in creation of this appendix.
*Power Calculations are not part of the data analysis but rather are 
*prospective analyses that were conducted prior to finalizing the research design.

*Discussion of power calculations is based on:
*3ie sample size Minimum Detectable Effect Calculator
*Citation: 
*Djimeu, EW and Houndolo, D-G, 2016. Power calculation for causal inference in 
*social science: sample size and minimum detectable effect determination, 
*3ie impact evaluation manual, 3ie Working Paper 26. 
*New Delhi: International Initiative for Impact Evaluation (3ie)

	
********************************************************************************
********Appendix C: Main Analyses: Individual Performance on Team Task
*(linear regression)

*Main analysis: OLS, NO controls, all treatments
eststo: regress Main_Effort i.treat_num ///
	SizeSession ///
	, robust cluster (groupid)
*test for differences between 2 deliberation treatments
test 3.treat_num = 4.treat_num
*test for differences between 2 majority rules treatments
test 1.treat_num = 2.treat_num

*Main analysis: OLS w/controls, all treatments
eststo: regress Main_Effort i.treat_num ///
	$Controls ///
	, robust cluster (groupid)
*test for differences between 2 deliberation treatments
test 3.treat_num = 4.treat_num
*test for differences between 2 majority rules treatments
test 1.treat_num = 2.treat_num

*Main analysis: OLS, NO controls, collapsed treatments 
*Note: collapsed version combines 2 deliberation treat groups and 2 maj rules groups
eststo: regress Main_Effort i.treat_coll ///
	SizeSession ///
	, robust cluster (groupid)

*Main analysis: OLS w/controls, collapsed treatments
eststo: regress Main_Effort i.treat_coll ///
	$Controls ///
	, robust cluster (groupid)


esttab using "App C Main Analysis - OLS .rtf", ///
	se obslast r2 label compress star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace
eststo clear	
	

********************************************************************************
********Appendix D: Main Analyses: Individual Performance on Team Task
*(poisson models)

*Main analysis: poisson, NO controls, all treatments
eststo: poisson Main_Effort i.treat_num ///
	SizeSession ///
	, robust cluster (groupid)
test 3.treat_num = 4.treat_num
test 1.treat_num = 2.treat_num

*Main analysis: poisson w/controls, all treatments
eststo: poisson Main_Effort i.treat_num ///
	$Controls ///
	, robust cluster (groupid)
test 3.treat_num = 4.treat_num
test 1.treat_num = 2.treat_num

*Main analysis: poisson, NO controls, collapsed treatments
eststo: poisson Main_Effort i.treat_coll ///
	SizeSession ///
	, robust cluster (groupid)

*Main analysis: poisson w/controls, collapsed treatments
eststo: poisson Main_Effort i.treat_coll ///
	$Controls ///
	, robust cluster (groupid)

esttab using "App D Main Analysis poisson.rtf", ///
	se obslast label compress star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace
eststo clear	


********************************************************************************
********Appendix E: Decision Quality vs. Behavior Change (Effort)
*(main models plus controls for ability)
	
eststo: regress Main_Effort i.treat_coll ///
	$Controls ///
	, robust cluster (groupid)	
est store	performance

eststo: regress MainTask_ability i.treat_coll ///
	$Controls ///
	, robust cluster (groupid)	
est store	ability

eststo: regress Main_Effort MainTask_ability i.treat_coll ///
	$Controls ///
	, robust cluster (groupid)	
est store	effort

eststo: probit ChoseBest i.treat_collapsed ///
	prop_female numCoethnic SizeSession ///
	if seq==1, robust
	margins, dydx(*) post
est store	decision	

esttab using "App E DecisionVsEffort.rtf", ///
	se obslast label compress star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace
eststo clear	
	

********************************************************************************
********Figure 2: Treatment Effects: Contributions, Ability, Effort, Decison Quality

*Show treatment effects from previous saved models (Appendix E)
coefplot (performance, label("Contributions (individual output on team task)")) ///
	(ability, label("Ability (output on individual task)")) ///
	(effort, label("Effort (contributions controlling for ability)")) , ///
	vertical legend(position(11) ring(0)) ///
	ciopts(recast(rcap) col(gs12)) ///
	yline(0) drop(1.treat_coll $Controls MainTask_ability 1.EverMarried _cons) nobase ///
	ytitle("Tasks Completed") 
graph save Graph "Figure2.gph", replace	



********************************************************************************
****Figure 3: Treatment Effects: Contributions, Ability, Effort, Decison Quality

*Group-level variable so use only 1 observation from each group:
cibar	ChoseBest if seq==1, over1(treat_collapse) ciopts(lcolor(gs12)) ///
		barcolor(gs7 teal ebblue) blsize(medlarge) /// 
		graph(ytitle("Pr(Made Best Choice)") ylab(0(.2)1) ///
		legend(position(6) col(3)) ) 		
graph save Graph "Figure3.gph", replace			
	

	
	
********************************************************************************
********Appendix F: Effects of Deliberation relative to Majority Rule group

*Same models as Appendix E, but excluding the control group from the analysis
eststo: regress Main_Effort i.treat_coll ///
	$Controls ///
	if treat_coll!=0 ///
	, robust cluster (groupid)	
est store	performance

eststo: regress MainTask_ability i.treat_coll ///
	$Controls ///
	if treat_coll!=0 ///
	, robust cluster (groupid)	
est store	ability

eststo: regress Main_Effort MainTask_ability i.treat_coll ///
	$Controls ///
	if treat_coll!=0 ///
	, robust cluster (groupid)	
est store	effort

eststo: probit ChoseBest i.treat_collapsed ///
	prop_female numCoethnic SizeSession ///
	if seq==1 &	treat_coll!=0 ///
	, robust
est store	decision	

esttab using "App F Deliberation vs MajRules.rtf", ///
	se obslast label compress star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace
eststo clear		
	
	
	
********************************************************************************
********Appendix G: Effects of Treatments on Secondary Outcomes 
	
eststo: probit GotPreference i.treat_coll ///
		$Controls ///
	, robust cluster (groupid)	
	margins, dydx(*) post
est store	prefagg

eststo: probit PrefChangePositive i.treat_coll ///
	$Controls ///
	, robust cluster (groupid)	
	margins, dydx(*) post
est store	prefchange

eststo: regress EQ6_TaskDecisionFairness i.treat_coll ///
	$Controls  ///
	, robust cluster (groupid)	
est store fairness		

eststo: regress EQ6_FinalTaskDecisionAgreement i.treat_coll ///
	$Controls FinalPrefMatch ///
	, robust cluster (groupid)	
est store agreement	

esttab using "App G Intermediate.rtf", se obslast label compress star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace
eststo clear	
	

********************************************************************************
****Figure 4: Treatment Effects - Secondary Outcomes
	
coefplot (prefagg, label("Preference Aggregation (Got Initial Preference)") ) (prefchange, label("Preference Change (Shifted to Team Preference)")) ///
	(agreement, label("Agreement with Team Decision")) (fairness, label("Perceived Decision as Fair")), ///
	vertical  legend(position(11) ring(0)) ///
	ciopts(recast(rcap) col(gs12)) ///
	yline(0) drop(1.treat_coll $Controls MainTask_ability 1.EverMarried _cons  FinalPrefMatch) nobase 
graph save Graph "Figure4.gph", replace		
	
			
********************************************************************************
********Appendix H: Effect of Intermediate Outcomes on Contributions

*Pref Alignment
eststo: regress Main_Effort $Controls GotPreference  ///
	, robust cluster (groupid)	
*Pref change : 
eststo: regress Main_Effort $Controls PrefChangePositive  ///
	, robust cluster (groupid)			

*Fairness not associated with greater effort 
eststo: regress Main_Effort $Controls EQ6_TaskDecisionFairness  ///
	, robust cluster (groupid)		
*Agreement with outcome --> greater contributions
eststo: regress Main_Effort $Controls EQ6_FinalTaskDecisionAgreement FinalPrefMatch  ///
	, robust cluster (groupid)		

esttab using "App H Intermediate on Contributions.rtf", se obslast label compress star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace
eststo clear	


********************************************************************************
********Appendix J: Effect of Intermediate Outcomes on Effort
*(Contributions controlling for Ability)
	
*Getting one's way associated with decreased effort (controlling for ability)
eststo: regress Main_Effort $Controls GotPreference  ///
	MainTask_ability ///
	, robust cluster (groupid)	
*Pref change : 
eststo: regress Main_Effort $Controls PrefChangePositive  ///
	MainTask_ability ///
	, robust cluster (groupid)	
*Fairness not associated with greater effort 
eststo: regress Main_Effort $Controls EQ6_TaskDecisionFairness  ///
	MainTask_ability ///
	, robust cluster (groupid)		
*Agreement with outcome --> greater effort
eststo: regress Main_Effort $Controls EQ6_FinalTaskDecisionAgreement FinalPrefMatch  ///
	MainTask_ability ///
	, robust cluster (groupid)		

esttab using "App J Intermediate on Effort.rtf", ///
	se obslast label compress star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace
eststo clear	
		
	
********************************************************************************
********Appendix K: Explanatory Notes: Deviations from PAP 

*No stata output was used in creation of this appendix
*This discussion and related analysis was conducted manually based on 
*knowledge of the research design and a direct comparison between the PAP and 
*the actual analyses conducted above.

	

********************************************************************************
********Appendix L: Adjustments for Multiple Hypothesis Testing

*No stata output was used in creation of this appendix
*This discussion and related analysis was conducted manually based on 
*simple arithemetic following the sequential Bonferroni correction procedure
*described within the Appendix.

	

	
********************************************************************************
***Causal Mediation Analysis 
*No figures/tables presented in paper, but analysis is referenced briefly in text

*No factor variables allowed in medeff, so modify Controls global:
global Controls2 = "Female Age educ_years EverMarried NoofChildren altruism KnewOthers prop_female numCoethnic SizeSession"
	
*DELIBERATION --> PREFERENCE CHANGE --> EFFORT
*Compared to Control Group Only:
medeff (probit PrefChangePositive Deliberation $Controls2 ) ///
	(regress Main_Effort Deliberation PrefChangePositive MainTask_ability $Controls2) ///
	if treat_coll!=1, ///
	mediate(PrefChangePositive) treat(Deliberation) ///
	sims(300) seed(316) vce(cluster groupid) 
medsens (probit PrefChangePositive Deliberation $Controls2) ///
	(regress Main_Effort Deliberation PrefChangePositive MainTask_ability $Controls2) ///
	if treat_coll!=1, ///
	mediate(PrefChangePositive) treat(Deliberation) ///
	sims(300) graph
*Compared to ALL (mixed group of control and maj rules treatment):
medeff (probit PrefChangePositive Deliberation $Controls2 ) ///
	(regress Main_Effort Deliberation PrefChangePositive MainTask_ability $Controls2) ///
	, ///
	mediate(PrefChangePositive) treat(Deliberation) ///
	sims(300) seed(316) vce(cluster groupid) 
medsens (probit PrefChangePositive Deliberation $Controls2) ///
	(regress Main_Effort Deliberation PrefChangePositive MainTask_ability $Controls2) ///
	, ///
	mediate(PrefChangePositive) treat(Deliberation) ///
	sims(300) graph		
	
	
*DELIBERATION --> PREFERENCE ALIGNMENT --> CONTRIBUTIONS
*Compared to Control Group Only:
medeff (probit GotPreference Deliberation $Controls2 ) ///
	(regress Main_Effort Deliberation GotPreference $Controls2) ///
	if treat_coll!=1, ///
	mediate(GotPreference) treat(Deliberation) ///
	sims(300) seed(316) vce(cluster groupid) 
medsens (probit GotPreference Deliberation $Controls2) ///
	(regress Main_Effort Deliberation GotPreference $Controls2) ///
	if treat_coll!=1, ///
	mediate(GotPreference) treat(Deliberation) ///
	sims(300) graph
*Compared to ALL (mixed group of control and maj rules treatment):
medeff (probit GotPreference Deliberation $Controls2 ) ///
	(regress Main_Effort Deliberation GotPreference $Controls2) ///
	, ///
	mediate(GotPreference) treat(Deliberation) ///
	sims(300) seed(316) vce(cluster groupid) 
medsens (regress GotPreference Deliberation $Controls2) ///
	(regress Main_Effort Deliberation GotPreference $Controls2) ///
	, ///
	mediate(GotPreference) treat(Deliberation) ///
	sims(300) graph	
		


		

********************************************************************************
********Table 1: Descriptive Statistics about Preferences & Choices
	
*generate variable that shows how majority preference (>=3) in pre-treat survey
*mapped to best choice for team (based on practice round data)
gen PrefAggBestChoice = .
replace PrefAggBestChoice = 0 if PrefAggBest==0
replace PrefAggBestChoice = 1 if PrefAggBest==1 & PrefAgg==.
replace PrefAggBestChoice = 2 if PrefAggBest==1 & PrefAgg!=.
label define PrefAggBestChoice 0 "Not Preferred" 1 "Tied for Top Choice" 2 "Top Preference"
label values PrefAggBestChoice PrefAggBestChoice


*Among those teams for whom best choice was top preference in pre-treatment survey,
*how many in each treatment group actually chose best through decision process?
tab ChoseBest treat_coll if seq==1 & treat_coll!=0 & PrefAggBestChoice==2

*Among those teams for whom best choice was tied for top in pre-treatment survey,
*how many in each treatment group actually chose best through decision process?
tab ChoseBest treat_coll if seq==1 & treat_coll!=0 & PrefAggBestChoice==1

*Among those teams for whom best choice was not preferred in pre-treatment survey,
*how many in each treatment group actually chose best through decision process?
tab ChoseBest treat_coll if seq==1 & treat_coll!=0 & PrefAggBestChoice==0



clear all
log close


********************************************************************************	
********************************END OF DO FILE**********************************	
********************************************************************************	
	
 
 

